﻿using System;
using Csla.Xaml;
using Accounting.Library;
using Utility;

namespace csla4Skeleton.UI.SL.TongHop.TH_KyKetChuyen
{
    public class TH_KyKetChuyen_ViewModel : ViewModel<Accounting.Library.TH_KyKetChuyen>
    {
        #region Event Declare
        public delegate void ChildList_AddedNew_EventHandler(object sender, ChildListAddedNewArgs e);
        public event ChildList_AddedNew_EventHandler ChildList_AddedNew;
        #endregion

        #region Refresh Model

        public void SaveAndNew()
        {
            BeginSave();
            NewTH_KyKetChuyen_ViewModel();
        }

        public void NewTH_KyKetChuyen_ViewModel()
        {
            BeginRefresh("NewTH_KyKetChuyen");
        }

        public TH_KyKetChuyen_ViewModel()
        {
            BeginRefresh("NewTH_KyKetChuyen");
        }

        public TH_KyKetChuyen_ViewModel(int VoucherId)
        {
            BeginRefresh("GetTH_KyKetChuyen", VoucherId);
        }

        public void GetTH_KyKetChuyen_ViewModel(int VoucherId)
        {
            BeginRefresh("GetTH_KyKetChuyen", VoucherId);
        }
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                Model.TH_KyKetChuyen_ChiTiets.AddedNew += new EventHandler<Csla.Core.AddedNewEventArgs<TH_KyKetChuyen_ChiTietChild>>(TH_KyKetChuyen_ChiTiets_AddedNew);
            }
        }
        #endregion

        #region Add Order Details Item
        public void AddOrderDetailsItem()
        {
            Model.TH_KyKetChuyen_ChiTiets.AddNewItem(Model.Khoa);
        }

        void TH_KyKetChuyen_ChiTiets_AddedNew(object sender, Csla.Core.AddedNewEventArgs<TH_KyKetChuyen_ChiTietChild> e)
        {
            OnChildList_AddedNew(sender, new ChildListAddedNewArgs("TH_KyKetChuyen_ChiTiets"));
        }

        protected virtual void OnChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (ChildList_AddedNew != null)
            {
                //Invokes the delegates.
                ChildList_AddedNew(sender, e);
            }
        }
        #endregion

        #region View Model Relate Methods
        public void TransferInBookVoucher()
        {
            //this.Model.TransferredMode = true;
            this.BeginSave();
            BeginRefresh("GetTH_KyKetChuyen", Model.Khoa);
        }

        public void RemoveInBookVoucher()
        {
            //this.Model.TransferredMode = true;
            BeginRefresh("DeleteTH_KyKetChuyen", Model.Khoa);
            //NewOrderViewModel();
        }
        #endregion
    }
}
